package com.vishop.models;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import org.hibernate.annotations.CollectionId;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

@Entity
public class Bestelling {
	@Id	@GeneratedValue(strategy=GenerationType.AUTO)
	private int bestellingId;
	@Column private Date datum;
	@Column private double totaalPrijs;
	@ManyToOne(cascade=CascadeType.PERSIST)
	@JoinColumn(name="persoonId")
	private Persoon persoon;
	@ManyToMany
	@JoinTable(name="BestellingRegels", joinColumns=@JoinColumn(name="bestellingId"),
	inverseJoinColumns=@JoinColumn(name="productId"))
	@GenericGenerator(name="hilo-gen", strategy="hilo")
	@CollectionId(columns = { @Column(name="bestellingRegelId") }, generator = "hilo-gen", type = @Type(type="long"))
	private Collection<Product> product =  new ArrayList<Product>();
	
	//constructor
	public Bestelling(){	
	}
	
	public Bestelling(int bestellingId, Date datum, double totaalPrijs, Persoon persoon,Collection<Product> product){
		super();
		this.product = product;
		this.bestellingId = bestellingId;
		this.totaalPrijs = totaalPrijs;
		this.datum = datum;
		this.persoon = persoon;
	}

	//getters en setters
	public Persoon getPersoon() {
		return persoon;
	}
	public void setPersoon(Persoon persoon) {
		this.persoon = persoon;
	}
	public Collection<Product> getProduct() {
		return product;
	}
	public void setProduct(Collection<Product> product) {
		this.product = product;
	}
	public int getBestellingId() {
		return bestellingId;
	}
	public void setBestellingId(int bestellingId) {
		this.bestellingId = bestellingId;
	}
	public Date getDatum() {
		return datum;
	}
	public void setDatum(Date datum) {
		this.datum = datum;
	}
	public double getTotaalPrijs() {
		return totaalPrijs;
	}
	public void setTotaalPrijs(double totaalPrijs) {
		this.totaalPrijs = totaalPrijs;
	}
}
